//引入创建Slice包
import {
    createSlice
} from '@reduxjs/toolkit'

//创建Slice
const countSlice = createSlice({

    //action中type的命名前缀
    name: "count",

    //reducer的初始值
    initialState: {
        count: 0
    },

    //reducer
    reducers: {
        increment(prev , action){
            prev.count += action.payload
        },
        decrement(prev , action){
            prev.count -= action.payload
        }
    },
})

//默认暴露Slice中的reducer
export default countSlice.reducer

//分别暴露action
export const {
    increment,
    decrement
} = countSlice.actions